home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / Snippets / Printing / Scalable PostScript PICT / Template.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-24  |  2.3 KB  |  110 lines  |  [TEXT/KAHL]

  1. // Template to create a picture that contains PostScript
  2. // which scales as it's drawn 
  3.  
  4. #include "PrintComments.h"
  5.  
  6. PicHandle DoPicture(void);
  7. Handle StuffInHandle(const Str255 theString);
  8.  
  9. /*------ main ----------------------------------------------------------------------------*/
  10.  
  11. PicHandle myPicture;
  12.  
  13. main()
  14.  
  15. {
  16.  
  17. GrafPort myPort;
  18.  
  19.  
  20.     InitGraf((Ptr) &thePort);
  21.     OpenPort(&myPort);
  22.     InitFonts();
  23.     InitWindows();
  24.     InitMenus();
  25.     TEInit();
  26.     InitDialogs(nil);
  27.     InitCursor();
  28.  
  29.       myPicture = DoPicture();                   // make and publish our picture
  30.  
  31. } /* main */
  32.  
  33.  
  34.  
  35.  
  36. /*------ DoPicture ----------------------------------------------------------------------*/
  37.  
  38. PicHandle DoPicture (void)
  39.  
  40. {
  41.     Rect myRect;
  42.     PicHandle thePicHandle;
  43.     GrafPort myPort;
  44.     long scrapResult;
  45.     unsigned long thePictureSize;
  46.     PixPatHandle thePixPat;
  47.     short theFont, textSize = 14;
  48.     Handle myHandle;
  49.     
  50.     const Str255 myString = 
  51.          "\pclippath pathbbox 4 copy moveto lineto 4 1 roll exch moveto exch lineto stroke\r";
  52.  
  53.     OpenPort(&myPort);
  54.     SetRect(&myRect,0,0,200,200);
  55.     thePicHandle = OpenPicture(&myRect);
  56.     ClipRect(&myRect);
  57.     
  58.     MoveTo(22,22);
  59.     LineTo(55,55);
  60.     LineTo(58,22);
  61.     LineTo(22,58);
  62.     
  63.     GetFNum ("\pTimes", &theFont);
  64.     TextFont (theFont);
  65.     TextSize (textSize);
  66.     
  67.     SetRect(&myRect,50,50,100,150);
  68.     ClipRect(&myRect);
  69.     
  70.     MoveTo(0,0);
  71.     LineTo(0,0);                // flush the QuickDraw changes to the clip
  72.     
  73.     PicComment(PostScriptBegin,0,NULL);
  74.     myHandle = StuffInHandle(myString);
  75.     PicComment(PostScriptHandle,myString[0],myHandle);
  76.     DisposHandle(myHandle);
  77.     PicComment(PostScriptEnd,0,NULL); 
  78.  
  79.     SetRect(&myRect,0,0,200,200);
  80.     ClipRect(&myRect);
  81.     
  82.     MoveTo(100,50);
  83.     DrawString("\pA wonderful test");
  84.     
  85.     ClosePicture();
  86.     ClosePort(&myPort);
  87.     
  88.     thePictureSize = GetHandleSize((Handle)thePicHandle);
  89.  
  90.     ZeroScrap();
  91.     HLock((Handle)thePicHandle);
  92.     scrapResult = PutScrap(GetHandleSize((Handle)thePicHandle),'PICT',StripAddress(*thePicHandle));
  93.     HUnlock((Handle)thePicHandle);
  94.  
  95.     KillPicture(thePicHandle);            // don't forget to clean up after yourself
  96.     
  97. }  /* InitPicture */
  98.  
  99. /*------ StuffInHandle ----------------------------------------------------------------------*/
  100.  
  101.  
  102. Handle StuffInHandle(const Str255 theString)
  103. {
  104.     Handle theHandle = NewHandle(theString[0]);
  105.     HLock(theHandle);
  106.     BlockMove((Ptr)&theString[1],*theHandle,theString[0]);
  107.     HUnlock(theHandle);
  108.     return(theHandle);
  109. }
  110.